//创建加载动画效果
import "./index.scss"; //引入对应的scss文件
import "../../style/font_icon/iconfont.css"; //引入对应的icon图标文件
let newArr = [];
export function showLoading() {
  let maskloading = document.createElement("div"); //创建div元素(mask)
  let loading = document.createElement("span"); //创建loading元素
  maskloading.className = "maskloading"; //给应的div起类名
  loading.className = "iconfont icon-loading"; //给loading起类名
  maskloading.appendChild(loading); //将loading作为孩子添加到mask
  document.querySelector("#loadcon").appendChild(maskloading); //最后将mask添加到body中

  let index = setTimeout(() => {
    for (let i = 0; i < newArr.length; i++) {
      if ((index = newArr[i].index)) {
        let data = newArr.splice(i, 1)[0];
        document.querySelector("#loadcon").removeChild(data.node);
        alert("请求超时");
      }
    }
  }, 6000);

  newArr.push({ index, node: maskloading });
}
export function hiddenLoading() {
  if (newArr.length > 0) {
    let data = newArr.splice(0, 1)[0];
    clearTimeout(data.index);
    document.querySelector("#loadcon").removeChild(data.node);
  }
}
